#ifndef DELTATIMER_HPP_
#define DELTATIMER_HPP_

class deltaTimer
{
	LARGE_INTEGER start;
	LARGE_INTEGER end;
	LARGE_INTEGER freq;
	float m_fDeltaTime;
	unsigned int m_unFPS;
	int m_nFrames;
	float  m_fTimer;
	

private:

	deltaTimer( void ):m_fDeltaTime(0.0)
	{
		m_fTimer = 0;
		m_nFrames = 0;
		freq.QuadPart = LONGLONG( 0.0 );
		QueryPerformanceFrequency( &freq ); Start();
	}
	~deltaTimer( void ){}
	deltaTimer( deltaTimer& ){}

public:

	static deltaTimer* GetInstanceRender()
	{
		static deltaTimer RenderTimer;
		return &RenderTimer;
	}
	
	static deltaTimer* GetInstanceUpdate()
	{
		static deltaTimer UpdateTimer;
		return &UpdateTimer;
	}


	void Start( void ){ QueryPerformanceCounter( &start ); }

	void End( void ) { QueryPerformanceCounter( &end ); }

	void Update( void )
	{
		End();
		m_fDeltaTime = ( float( ( end.QuadPart  - start.QuadPart ) / ( float )freq.QuadPart ) );


		++m_nFrames;
		m_fTimer += m_fDeltaTime;	
		
		if(m_fTimer >= 1)
		{
			m_unFPS = m_nFrames/ int(m_fTimer);
			m_nFrames = 0;
			m_fTimer = 0.0f;
		}

		Start();	
	}
	
	unsigned int GetFPS()
	{
		return m_unFPS;
	}

	float GetDelta( void )
	{
		return m_fDeltaTime; 
	}

};

#endif